<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Child</title>
    <script src="../../dist/post-message-bus.umd.js"></script>
</head>

<body>
    <div>value: <span id="value"></span></div>
    <ol id="log"></ol>
    <script>
        var log = msg => {
            const node = document.createElement("li");
            document.querySelector("#log").appendChild(node);
            node.textContent = msg;
            console.log(`[${location.pathname}] `, msg);
        }
    </script>
    <script>
        const bus = PostMessageBus.generateBusToParent({
            getName: function () {
                return "Tim Cook";
            },
            sendDate: function (d) {
                log(`received parent date: ${d}`);
            },
            updateValue: function (value) {
                document.getElementById("value").textContent = value;
                return `[${location.pathname}] 更新成功`;
            }
        });
        bus.echo(location.href).then(greet => log(greet));
    </script>
</body>

</html>